


var carousel = document.querySelector('#carousel')
var items = carousel.children
//console.log(items)
var prevBtn = document.querySelector('#prev')
var nextBtn = document.querySelector('#next')

//这里是向下翻页部分
index = 0;
nextBtn.addEventListener('click',function(){
    items[index].className = ''
    if(index === items.length - 1){
        index = -1
    }

    index ++
    items[index].className = 'active'
})

//这里是向上翻页部分
prevBtn.addEventListener('click',function(){
    items[index].className = ''
    if(index === 0){
        index = items.length
    }

    index --
    items[index].className = 'active'


})


//5.定时器

// setTimeout(function()  {
//    console.log('suprise!') 
// }, 2000);//2000毫秒后执行

var timer = setInterval(function()  {
   console.log('这个会间隔2秒执行一次!') 
}, 2000);

setTimeout(function()  {
    clearInterval(timer)
}, 6000);


setInterval(function()  {
     items[index].className = ''
     if(index === items.length - 1){
         index = -1
     }

     index ++
     items[index].className = 'active'
 }, 3000);//自动播放轮播图




 
